﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using System.Collections.Generic;
namespace WPFExcelReport
{
    public partial class UIVKQA : ViewBase
    {
        public UIVKQA()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return; 
            base.Window_Loaded(sender, e); 
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            try
            {               
                if (dwMaster == null)
                {
                }
                else
                { 
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
                MessageBox.Show(ex.Message);
            }
        }

        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            base.EditCommand(sender, e);
        }

        public override void DeleteCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            base.DeleteCommand(sender, e);            
        }

        public override void CopyCommand(object sender, System.Windows.RoutedEventArgs e)
        {           
            vwMaster.View.MoveCurrentToFirst();

        }
        
        public virtual void OnROWNIDChg(string value)
        {
            try
            {
                if (ROWNID == "0") return;
                dwData = TBMain.NewRow();
                dwData["MANDANT"] = app.Mandant;
                dwData["ROWNID"] = value.Trim();
                SResult = TMV.QVKA1(dwData);
                MergeData(SResult, false);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public virtual void OnCARTChg(string value)
        { }

    }
    public partial class UIVKQA : ViewBase
    {
        public VICC_VKQA TMV
        {
            get
            {
                return (VICC_VKQA)MV;
            }
        }
        #region ==CART===========
        public static readonly DependencyProperty CARTProperty = DependencyProperty.Register("CART",
            typeof(string), typeof(UIVKQA),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCARTChanged));
        public string CART
        {
            get
            {
                return (string)GetValue(CARTProperty);
            }
            set
            {
                SetValue(CARTProperty, value);
                OnCARTChg(value); 
            }
        }
        private static void OnCARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKQA;
            if (src != null)
            {
                src.CART = (string)e.NewValue;
            }
        }
        #endregion
        #region ==ROWNID===========
        public static readonly DependencyProperty ROWNIDProperty = DependencyProperty.Register("ROWNID",
            typeof(string), typeof(UIVKQA),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnROWNIDChanged));
        public string ROWNID
        {
            get
            {
                return (string)GetValue(ROWNIDProperty);
            }
            set
            {
                SetValue(ROWNIDProperty, value);
                OnROWNIDChg(value);
            }
        }
        private static void OnROWNIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVKQA;
            if (src != null)
            {
                src.ROWNID = (string)e.NewValue;
            }
        }
        #endregion
    }
}
